package com.tuo51.foudation.query;

import com.tuo51.foudation.exception.BusinessException;
import com.tuo51.foudation.model.ErrorCode;
import com.tuo51.foudation.query.base.PagerQuery;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * *******************************
 * Created by Ron.
 * form com.tuo51
 * on 2017/12/21
 * *******************************
 */

@Data
@EqualsAndHashCode(callSuper = true)
public class EvaluateQuery extends PagerQuery {

    private String childrenId;

    private String staffId;

    private String childrenName;

    private Integer month;

    private Integer orderStatus;

    private Integer status;

    private String orderBy;

    private String sequence;

    private String phone;

    public void validateOrderByAndSequence(){

        if( (StringUtils.isNotBlank(getOrderBy())
                && !"created".equalsIgnoreCase(getOrderBy())
                && !"status".equalsIgnoreCase(getOrderBy())
                && !"month".equalsIgnoreCase(getOrderBy())
                && !"weight".equalsIgnoreCase(getOrderBy())
                && !"height".equalsIgnoreCase(getOrderBy())
                && !"header".equalsIgnoreCase(getOrderBy())
                && !"published".equalsIgnoreCase(getOrderBy())
                && !"birthday".equalsIgnoreCase(getOrderBy())
        )
                || (StringUtils.isNotBlank(getSequence()) && !"desc".equalsIgnoreCase(getSequence()) && !"asc".equalsIgnoreCase(getSequence())) ){
            throw new BusinessException(ErrorCode.UNDEFINED, "参数错误");
        }

    }

}
